package service.impl;

import bean.RoomBean;
import bean.RoomFacilitiesBean;
import mapper.IRoomFacilitiesMapper;
import service.IRoomFacilitiesService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class RoomFacilitiesServiceImpl extends BaseService implements IRoomFacilitiesService {
    @Override
    public List<RoomFacilitiesBean> getRoomFacilities(int id) {
        SqlSession session = this.getSession();
        IRoomFacilitiesMapper mapper = session.getMapper(IRoomFacilitiesMapper.class);
        List<RoomFacilitiesBean> list = mapper.getRoomFacilities(id);
        session.close();
        return list;
    }

    @Override
    public void insertDamage(RoomFacilitiesBean roomFacilitiesBean, Integer roomId) {
        SqlSession session = this.getSession();
        IRoomFacilitiesMapper mapper = session.getMapper(IRoomFacilitiesMapper.class);
        mapper.insertDamage(roomFacilitiesBean, roomId);
        session.commit();
        session.close();

    }

    @Override
    public void TreatmentFacilities(Integer facilitiesId, Integer roomId) {
        SqlSession session = this.getSession();
        IRoomFacilitiesMapper mapper = session.getMapper(IRoomFacilitiesMapper.class);
        mapper.updateSolve(facilitiesId);
        int ontSolveCount = mapper.solveCount(roomId);
        if (ontSolveCount == 0) {
            mapper.updateStatus(roomId);
        }
        session.commit();
        session.close();
    }
}
